//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.imagemanager.util;

import android.graphics.Color;

public final class Shared {
    public static final int INVALID = -1;
    public static final int INFINITY = 2147483647;

    public Shared() {
    }

    public static int argb(float a, float r, float g, float b) {
        return Color.argb((int)(a * 255.0F), (int)(r * 255.0F), (int)(g * 255.0F), (int)(b * 255.0F));
    }

    public static boolean isPowerOf2(int n) {
        return (n & -n) == n;
    }

    public static int midPointIterator(int i) {
        if(i != 0) {
            int tick = (i - 1) / 2 + 1;
            int pass = (i - 1) % 2 == 0?1:-1;
            return tick * pass;
        } else {
            return 0;
        }
    }

    public static int nextPowerOf2(int n) {
        --n;
        n |= n >>> 16;
        n |= n >>> 8;
        n |= n >>> 4;
        n |= n >>> 2;
        n |= n >>> 1;
        return n + 1;
    }

    public static int prevPowerOf2(int n) {
        return isPowerOf2(n)?nextPowerOf2(n):nextPowerOf2(n) - 1;
    }

    public static int clamp(int value, int min, int max) {
        if(value < min) {
            value = min;
        } else if(value > max) {
            value = max;
        }

        return value;
    }

    public static long clamp(long value, long min, long max) {
        if(value < min) {
            value = min;
        } else if(value > max) {
            value = max;
        }

        return value;
    }

    public static float scaleToFit(float srcWidth, float srcHeight, float outerWidth, float outerHeight, boolean clipToFit) {
        float var10000;
        float scaleX;
        label23: {
            scaleX = outerWidth / srcWidth;
            float scaleY = outerHeight / srcHeight;
            if(clipToFit) {
                if(scaleX > scaleY) {
                    break label23;
                }
            } else if(scaleX < scaleY) {
                break label23;
            }

            var10000 = scaleY;
            return var10000;
        }

        var10000 = scaleX;
        return var10000;
    }

    public static float normalizePositive(float angleToRotate) {
        if(angleToRotate == 0.0F) {
            return 0.0F;
        } else {
            float nf = angleToRotate / 360.0F;
            int n = 0;
            if(angleToRotate < 0.0F) {
                n = (int)(nf - 1.0F);
            } else if(angleToRotate > 360.0F) {
                n = (int)nf;
            }

            angleToRotate -= (float)n * 360.0F;
            if(angleToRotate == 360.0F) {
                angleToRotate = 0.0F;
            }

            return angleToRotate;
        }
    }

    public static int degreesToExifOrientation(float normalizedAngle) {
        return normalizedAngle == 0.0F?1:(normalizedAngle == 90.0F?6:(normalizedAngle == 180.0F?3:(normalizedAngle == 270.0F?8:1)));
    }

    public static float exifOrientationToDegrees(int exifOrientation) {
        return exifOrientation == 6?90.0F:(exifOrientation == 3?180.0F:(exifOrientation == 8?270.0F:0.0F));
    }
}
